<?php



class Fee_logAction extends CommonAction

{

    public function index()

    {

		import('ORG.Util.Page');
        $Mal = D('Fee_log');
		
		
		
		if($this->_get('stime')){
			$map=' time between '.strtotime($this->_get('stime')).' and '.strtotime($this->_get('etime'));
			if($this->_get('keywords')){
			$map.=' and member_id = '.$this->_get('keywords');	
			}
		}
		if($this->_get('keywords')&&$this->_get('stime')==''){
			$map=' member_id = '.$this->_get('keywords');	
		}
		
		
		$count = $Mal->where($map)->order('id desc')->count();
		$Page = new Page($count);
        $this->list=$Mal->order('id desc')->where($map)->limit($Page->firstRow.','.$Page->listRows)->select();
		$this->pages = $Page->show();
		
		
        $this->display();

    }



    public function edit()

    {

		

        $id = $this->_get('id');

        $this->assign('AffiliateConfig', C('AffiliateConfig'));

        $db = M('Affiliatesetting');

        $info = $db->where(array('id' => $id))->find();

        import('@.ORG.Affiliate.' . $info['classname']);

        $affclass = $info['classname'];
		
		
        $aff = new $affclass(0, $this->siteid);

        $html = $aff->createform();

        $this->formhtml = $html;

        parent::edit();

    }



    public function update()

    {



        import('@.ORG.Affiliate.' . $this->_post('classname'));

        $affclass = $this->_post('classname');

        $aff = new $affclass(0, $this->siteid);



        if (!$aff->saveform()) {

            $this->error($aff->getError());

        }



        parent::update();

    }



    public function add()

    {

        $this->assign('AffiliateConfig', C('AffiliateConfig'));

        parent::add();

    }



    


 



    //确认分成

    public function confirm()

    {

        //dump($this -> _post('order_id'));exit;

        if ($this->_post('order_id')) {

            $db = D('Member_account_log');

            $order_id = $_POST['order_id'];

            $attr = $_POST['attr'];

            $product_id = $_POST['product_id'];

            foreach ($order_id as $k => $v) {

                $db->confirm($v, $product_id[$k], $attr[$k]);

            }

            $this->success('操作完成！');

        } else {

            $this->error('没有可分成的订单！');

        }

    }



    public function setQrcode()

    {

        if ($this->_post('qrcode')) {

            $data['qrcodesetting'] = serialize($_POST);

            $map['id'] = $this->siteid;

            $db = M('Site');

            $db->data($data)->where($map)->save();

            //echo $db -> getLastSql();

            $info = $db->where($map)->find();

            $this->assign(unserialize($info['qrcodesetting']));

            $this->success('设置成功', U('setQrcode'));

        } else {

            $map['id'] = $this->siteid;

            $db = M('Site');

            $info = $db->where($map)->find();

            $this->assign(unserialize($info['qrcodesetting']));

            //dump($info);

            $this->display();

        }

    }

}